import 'package:flutter/material.dart';
import 'package:proj_shop/roots/weibo/pages/find/find_hot_search.dart';
import 'package:proj_shop/roots/weibo/pages/mine/weibo_login_page.dart';
import 'package:proj_shop/roots/weibo/pages/weibo_index_page.dart';

class WeiboRoutes {
  static const String login = "/login";
  static const String index = "/index";
  static const String find_hot_serch = "/find_hot_serch";

  static Route generateRoutes(RouteSettings routeSettings) {
    switch (routeSettings.name) {
      case index:
        return MaterialPageRoute(builder: (_) => WeiboIndexPage());
      case find_hot_serch:
        return MaterialPageRoute(builder: (_) => HotSearchPage());
      case login:
      default:
        return MaterialPageRoute(builder: (_) => WeiboLoginPage());
    }
  }

  static final WeiboRoutes _instance = WeiboRoutes._internal();
  WeiboRoutes._internal();
  factory WeiboRoutes() {
    return _instance;
  }

  final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

  Future<dynamic> pushNamedAndRemoveAllStack(String newRouteName) {
    return navigatorKey.currentState.pushNamedAndRemoveUntil(
      newRouteName,
      (route) => route == null,
    );
  }
}
